summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2022-12-17 16:21:19 +0100
committerGitHub <noreply@github.com>2022-12-17 16:21:19 +0100
commitfa10374d39effc79b5b9ed789bf873030cb08d7f (patch)
tree0e4cac7d6e87771e8f18c0d3bba7d8e3cddbb2c7
parentMerge pull request #9457 from Kelebek1/silence_tfb (diff)
parentSignal buffer event on audio in/out system stop, and force remove all registered audio buffers (diff)
downloadyuzu-fa10374d39effc79b5b9ed789bf873030cb08d7f.tar
yuzu-fa10374d39effc79b5b9ed789bf873030cb08d7f.tar.gz
yuzu-fa10374d39effc79b5b9ed789bf873030cb08d7f.tar.bz2
yuzu-fa10374d39effc79b5b9ed789bf873030cb08d7f.tar.lz
yuzu-fa10374d39effc79b5b9ed789bf873030cb08d7f.tar.xz
yuzu-fa10374d39effc79b5b9ed789bf873030cb08d7f.tar.zst
yuzu-fa10374d39effc79b5b9ed789bf873030cb08d7f.zip
-rw-r--r--src/audio_core/device/audio_buffers.h8
-rw-r--r--src/audio_core/device/device_session.cpp6
-rw-r--r--src/audio_core/device/device_session.h5
-rw-r--r--src/audio_core/in/audio_in_system.cpp7
-rw-r--r--src/audio_core/out/audio_out_system.cpp7
5 files changed, 26 insertions, 7 deletions
diff --git a/src/audio_core/device/audio_buffers.h b/src/audio_core/device/audio_buffers.h
index 3dae1a3b7..15082f6c6 100644
--- a/src/audio_core/device/audio_buffers.h
+++ b/src/audio_core/device/audio_buffers.h
@@ -91,9 +91,10 @@ public:
* @param core_timing - The CoreTiming instance
* @param session - The device session
*
- * @return Is the buffer was released.
+ * @return If any buffer was released.
*/
- bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session) {
+ bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session,
+ bool force) {
std::scoped_lock l{lock};
bool buffer_released{false};
while (registered_count > 0) {
@@ -103,7 +104,8 @@ public:
}
// Check with the backend if this buffer can be released yet.
- if (!session.IsBufferConsumed(buffers[index])) {
+ // If we're shutting down, we don't care if it's been played or not.
+ if (!force && !session.IsBufferConsumed(buffers[index])) {
break;
}
diff --git a/src/audio_core/device/device_session.cpp b/src/audio_core/device/device_session.cpp
index 995060414..5a327a606 100644
--- a/src/audio_core/device/device_session.cpp
+++ b/src/audio_core/device/device_session.cpp
@@ -73,6 +73,12 @@ void DeviceSession::Stop() {
}
}
+void DeviceSession::ClearBuffers() {
+ if (stream) {
+ stream->ClearQueue();
+ }
+}
+
void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const {
for (const auto& buffer : buffers) {
Sink::SinkBuffer new_buffer{
diff --git a/src/audio_core/device/device_session.h b/src/audio_core/device/device_session.h
index 74f4dc085..75f766c68 100644
--- a/src/audio_core/device/device_session.h
+++ b/src/audio_core/device/device_session.h
@@ -91,6 +91,11 @@ public:
void Stop();
/**
+ * Clear out the underlying audio buffers in the backend stream.
+ */
+ void ClearBuffers();
+
+ /**
* Set this device session's volume.
*
* @param volume - New volume for this session.
diff --git a/src/audio_core/in/audio_in_system.cpp b/src/audio_core/in/audio_in_system.cpp
index 4324cafd8..934ef8c1c 100644
--- a/src/audio_core/in/audio_in_system.cpp
+++ b/src/audio_core/in/audio_in_system.cpp
@@ -23,7 +23,6 @@ System::~System() {
void System::Finalize() {
Stop();
session->Finalize();
- buffer_event->Signal();
}
void System::StartSession() {
@@ -102,6 +101,10 @@ Result System::Stop() {
if (state == State::Started) {
session->Stop();
session->SetVolume(0.0f);
+ session->ClearBuffers();
+ if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
+ buffer_event->Signal();
+ }
state = State::Stopped;
}
@@ -138,7 +141,7 @@ void System::RegisterBuffers() {
}
void System::ReleaseBuffers() {
- bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)};
+ bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
if (signal) {
// Signal if any buffer was released, or if none are registered, we need more.
diff --git a/src/audio_core/out/audio_out_system.cpp b/src/audio_core/out/audio_out_system.cpp
index a66208ed9..e096a1dac 100644
--- a/src/audio_core/out/audio_out_system.cpp
+++ b/src/audio_core/out/audio_out_system.cpp
@@ -24,7 +24,6 @@ System::~System() {
void System::Finalize() {
Stop();
session->Finalize();
- buffer_event->Signal();
}
std::string_view System::GetDefaultOutputDeviceName() const {
@@ -102,6 +101,10 @@ Result System::Stop() {
if (state == State::Started) {
session->Stop();
session->SetVolume(0.0f);
+ session->ClearBuffers();
+ if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
+ buffer_event->Signal();
+ }
state = State::Stopped;
}
@@ -138,7 +141,7 @@ void System::RegisterBuffers() {
}
void System::ReleaseBuffers() {
- bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)};
+ bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
if (signal) {
// Signal if any buffer was released, or if none are registered, we need more.
buffer_event->Signal();